package StringOperation.test4_19;

import listNodePractice.ListNode;

import java.util.List;

public class JudgeHuiWen {

    public  boolean test(String s){
        int left=0;
        int right=s.length()-1;
        while (left<right){
            if (s.charAt(left)!=s.charAt(right)){
                return   false;
            }
            left++;
            right--;
        }
        return  true;
    }



    ListNode left=null;
    boolean res=true;
    public  boolean test1(ListNode  head){
        left=head;
//        System.out.println(traverse(head));
       traverse(head);
        return  res;
    }
//  CKG TODO 2023/4/19:  这个返回值自己设计的不对    我这样也是可以的
    public  ListNode  traverse(ListNode  right){
        if (right==null){
            return  null;
        }
        traverse(right.next);
        res=res&&(left.val==right.val);
        left=left.next;
        return   right;
    }

//    public  boolean  traverse(ListNode right){
//        if (right==null){
//            return   true;
//        }
//        boolean r = traverse(right.next);
//        r=r&&(right.val==left.val);
//        left=left.next;
//
//        return  r;
//    }


    public static void main(String[] args) {
        JudgeHuiWen judgeHuiWen = new JudgeHuiWen();
//        System.out.println(judgeHuiWen.test("aba"));

        ListNode listNode1 = new ListNode(1);
        ListNode listNode2 = new ListNode(2);
        ListNode listNode3 = new ListNode(1);
        ListNode listNode4 = new ListNode(2);
        ListNode listNode5 = new ListNode(1);
        listNode1.next=listNode2;
        listNode2.next=listNode3;
        listNode3.next=listNode4;
        listNode4.next=listNode5;
        System.out.println(judgeHuiWen.test1(listNode1));


    }


}
